//
//  CourseViewCell.m
//  xpkc
//
//  Created by TopSageOSX on 15/1/29.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "CourseViewCell.h"

@implementation CourseViewCell{
    UILabel *classNameLabel;
    UILabel *teacherNameLabel;
    UILabel *progressLabel;
    UIView *progressBG;
    int total;
    int hadstudy;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //
        [self creatView];
    }
    return self;
}
- (void)creatView{
    CGFloat offwidth = 0.04*SCREEN_WIDTH;
    
    classNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(offwidth*2, 0, 70, 35)];
    classNameLabel.font = FONT_SYS_S;
    [self addSubview:classNameLabel];
    UIImageView *teacher = [[UIImageView alloc]initWithFrame:CGRectMake(offwidth*2+90, 11, 15, 15)];
    teacher.image = [UIImage imageNamed:@"Img_teacher"];
    [self addSubview:teacher];
    teacherNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(offwidth*2+105, 0, 40, 35)];
    teacherNameLabel.font = FONT_SYS_S;
    teacherNameLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:teacherNameLabel];
    
    UIView *progressView = [[UIView alloc]initWithFrame:CGRectMake(200, 10, 80, 15)];
    UIView *progressGray = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 15)];
    progressGray.layer.borderWidth = 8;
    progressGray.layer.borderColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1].CGColor;
    [progressView addSubview:progressGray];
    
    progressBG = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 15)];
    progressBG.layer.borderWidth = 8;
    progressBG.layer.borderColor = OrangeColor.CGColor;
    [progressView addSubview:progressBG];
    
    progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 15)];
    progressLabel.font = FONT_SYS_S;
    progressLabel.textColor = [UIColor darkGrayColor];
    progressLabel.textAlignment = NSTextAlignmentCenter;
    [progressView addSubview:progressLabel];
    [self addSubview:progressView];
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(offwidth, 34, SCREEN_WIDTH, 1)];
    line.layer.borderWidth = 0.5;
    line.layer.borderColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor;
    [self addSubview:line];
}
- (NSString *)className{
    return classNameLabel.text;
}
- (void)setClassName:(NSString *)className{
    classNameLabel.text = className;
}
- (NSString *)teacherName{
    return teacherNameLabel.text;
}
- (void)setTeacherName:(NSString *)teacherName{
    teacherNameLabel.text = teacherName;
}
- (int)studied{
    return hadstudy;
}
- (void)setStudied:(int)studied{
    progressLabel.text = [NSString stringWithFormat:@"%d/%d",studied,total];
    hadstudy = studied;
    if (total!=0) {
        [progressBG setFrame:CGRectMake(0, 0, 80.0*studied/total, 15)];
    }
}
- (int)study{
    return total;
}
- (void)setStudy:(int)study{
    progressLabel.text = [NSString stringWithFormat:@"%d/%d",hadstudy,study];
    total = study;
    if (study!=0) {
        [progressBG setFrame:CGRectMake(0, 0, 80.0*hadstudy/study, 15)];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
